package com.example.myapp.webView.ui;

import com.example.myapp.MainActivity;
import com.example.myapp.R;
import com.example.myapp.fragment.HomeActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;

public class WebViewToUrlActivity extends Activity implements OnClickListener {
	WebView webView;
	Button btn_touch;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_webviewtourl);
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		webView = (WebView) findViewById(R.id.webView_toUrl);
		btn_touch=(Button) findViewById(R.id.btn_touch);
		btn_touch.setOnClickListener(this);
		loadView();
	}
	
	private void loadView() {
		// TODO Auto-generated method stub
//		String url="https://www.baidu.com";
		String url="file:///android_asset/guide/test.html";
		webView.setWebViewClient(new WebViewClient());
		webView.loadUrl(url);
	}
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		Intent intent = new Intent(WebViewToUrlActivity.this, HomeActivity.class);
		startActivity(intent);
		finish();

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		// 重写onKeyDown，当浏览网页，WebView可以后退时执行后退操作。
		if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
			webView.goBack();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_touch:
			Toast.makeText(WebViewToUrlActivity.this, "点击", Toast.LENGTH_SHORT).show();
			break;

		default:
			break;
		}
	}
}
